package com.dk.controller;


import com.alibaba.fastjson.JSONObject;
import com.dk.data.Result;
import com.dk.em.ResultEnum;
import com.dk.entity.*;
import com.dk.service.IDtRecycleBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lebron
 * @since 2021-12-22
 */
@RestController
@RequestMapping("brandController")
@Api(value = "回收品牌类型")
public class DtRecycleBrandController {
    @Autowired
    private IDtRecycleBrandService brandService;
    @PostMapping("recycleBrand")
    @ApiIgnore(value = "回收品牌查询")
    public Result recycleType(){
        List<DtRecycleBrand> recycleBrand = brandService.selectList();
        return Result.response(ResultEnum.SUCCESS).setData(recycleBrand);
    }
    @PostMapping("typeBrand")
    @ApiIgnore(value = "回收品牌类型查询")
    @ApiImplicitParam(name = "id",value = "回收的类型id",required = true,paramType = "query")
    public Result typeBrand(@RequestParam("id")Integer id){
        List<DtBrandType> brandTypeList = brandService.typeBrandById(id);
        return Result.response(ResultEnum.SUCCESS).setData(brandTypeList);
    }
    @PostMapping("detailBrand")
    @ApiIgnore(value = "回收品牌细节查询")
    @ApiImplicitParam(name = "id",value = "回收的类型id",required = true,paramType = "query")
    public Result detailBrand(@RequestParam("id")Integer id){
        List<DtDeatilType> deatilTypeList = brandService.detailBrandById(id);
        return Result.response(ResultEnum.SUCCESS).setData(deatilTypeList);
    }
    @PostMapping("specBrand")
    @ApiIgnore(value = "回收品牌细节查询")
    @ApiImplicitParam(name = "id",value = "回收的类型id",required = true,paramType = "query")
    public Result specBrand(@RequestParam("id")Integer id){
        List<DtSpec> specList = brandService.specBrandById(id);
        return Result.response(ResultEnum.SUCCESS).setData(specList);
    }
    @PostMapping("insertRecycle")
    @ApiIgnore(value = "回收商品的详细信息")
    @ApiImplicitParam(name = "recycle",value = "回收商品实体类",required = true,paramType = "query")
    public Result insertRecycle(@RequestBody DtCtcRecycle recycle){
        recycle.setUid(1);
        int i  = brandService.insertRecycle(recycle);
        return Result.response(ResultEnum.SUCCESS);
    }
    @PostMapping("sameProduct")
    @ApiIgnore(value = "卖同款")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goods",value = "商品实体类",required = true,paramType = "query"),
            @ApiImplicitParam(name = "item",value = "商品明细表",required = true,paramType = "query")
    })
    public Result sameProduct(@RequestParam("goods") String goods,@RequestParam("item") String item){

        DtGoods dtGoods = JSONObject.parseObject(goods, DtGoods.class);
        DtItem dtItem = JSONObject.parseObject(item, DtItem.class);
        int i = brandService.insertGoodsAndItem(dtGoods, dtItem);
        return Result.ok();
    }



}
